#include <bits/stdc++.h>
#define debug(x) cout << x << endl;
using namespace std;

const int N = 16;

typedef long long LL;

int n;
int a[N];

int main()
{
	freopen("color.in", "r", stdin);
	freopen("color.out", "w", stdout);
	int T;
	cin >> T;
	while(T --)
	{
		cin >> n;
		int res = 0;
		for(int i = 0; i < n; ++ i) cin >> a[i];
		for(int i = 0; i < 1 << n; ++ i)
		{
			int s0 = -1, s1 = -1;
			int sum = 0;
			for(int j = n - 1; j; -- j)
			{
				int pos = n - 1 - j;
				if(i >> j & 1)
				{
					if(s1 != -1 && a[pos] == a[s1]) sum += a[s1];
					s1 = pos;
				}
				else
				{
					if(s0 != -1 && a[pos] == a[s0])	sum += a[s0];
					s0 = pos;
				}
			}
			res = max(res, sum);
		}
		cout << res << endl;
	}
		
	return 0;
}
